package com.baseweb.webadmin.core.constants;

import com.baseweb.webadmin.core.model.pojo.ByUserBizAuth;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.List;

public enum AuthType {
    BIZ_AUTH(1, "平台认证"), PLATFORM(2, "诚信认证"), COLLEGE(3, "学院认证");

    private int code;
    private String name;

    AuthType(int code, String name) {
        this.code = code;
        this.name = name;
    }

    public int getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public static List<AuthType> getAllData() {
        List<AuthType> result = new ArrayList<AuthType>();
        for (AuthType current : AuthType.values()) {
            result.add(current);
        }
        return result;
    }

    public static List<AuthType> getUnAuthData(String authListStr) {
        List<AuthType> result = new ArrayList<AuthType>();

        for (AuthType current : AuthType.values()) {
            if (StringUtils.isBlank(authListStr) || authListStr.indexOf("" + current.getCode()) == -1) {
                result.add(current);
            }
        }
        return result;
    }

    public static AuthType getNameByCode(int code) {
        List<AuthType> allData = getAllData();
        for (AuthType status : allData) {
            if (status.getCode() == code) {
                return status;
            }
        }
        return null;
    }

    public static List<String> getTypeOpt() {
        List<String> list = new ArrayList<>();
        for (AuthType current : AuthType.values()) {
            String string = current.getCode() + ";" + current.getName();
            list.add(string);
        }
        return list;
    }
    public static List<String> getRestOpt(List<ByUserBizAuth> list){
        List<String> listRest = new ArrayList<>();
        if(list != null && list.size()>0){
            int authTypeH = list.get(0).getAuthType();
            if(authTypeH == 1){
                AuthType systemAuth = AuthType.values()[1];
                listRest.add(systemAuth.getCode() + ";" + systemAuth.getName());
                AuthType systemAuth1 = AuthType.values()[2];
                listRest.add(systemAuth1.getCode() + ";" + systemAuth1.getName());
            }else if(authTypeH == 2){
                AuthType systemAuth = AuthType.values()[2];
                listRest.add(systemAuth.getCode() + ";" + systemAuth.getName());
            } if(authTypeH == 3){
                if(list.size()>=3){
                    if(list.get(0).getAuthLevel() != 7 || list.get(0).getAuthLevel() != 14){
                        AuthType systemAuth = AuthType.values()[2];
                        listRest.add(systemAuth.getCode() + ";" + systemAuth.getName());
                    }
                }else {
                    AuthType systemAuth = AuthType.values()[1];
                    listRest.add(systemAuth.getCode() + ";" + systemAuth.getName());
                }
            }
            return listRest;
        }else {
            AuthType systemAuth = AuthType.values()[0];
            listRest.add(systemAuth.getCode() + ";" + systemAuth.getName());
            return listRest;
        }
    }
    public static void main(String[] args) {
        List<ByUserBizAuth> list = new ArrayList<>();
        ByUserBizAuth a = new ByUserBizAuth();
        a.setAuthType(3);
        list.add(a);
        System.out.println(getRestOpt(list));
    }
}
